package com.heima.article.controller;

import com.heima.article.service.ApArticleService;
import com.heima.common.contants.ArticleConstants;
import com.heima.model.article.dtos.ArticleHomeDto;
import com.heima.model.article.pojos.ApArticle;
import com.heima.model.common.dtos.ResponseResult;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

/**
 * 文章控制类
 *
 * @author xiaquanen
 * @version 1.0
 * @project heima-leadnews
 * @date 2024/7/18 21:48:20
 */
@RestController
@RequestMapping("/api/v1/article")
@Slf4j
@Api(tags = "文章模块")
public class ArticleController {

    @Autowired
    private ApArticleService apArticleService;

    /**
     * 查看全文
     *
     * @param dto
     * @return
     */
    @PostMapping("/load")
    public ResponseResult load(@RequestBody ArticleHomeDto dto) {
        ResponseResult load = apArticleService.load(dto, ArticleConstants.LOADTYPE_LOAD_MORE);
        return load;
    }

    /**
     * 查看更多
     *
     * @param dto
     * @return
     */
    @PostMapping("/loadmore")
    public ResponseResult loadMore(@RequestBody ArticleHomeDto dto) {
        return apArticleService.load(dto,ArticleConstants.LOADTYPE_LOAD_MORE);
    }

    /**
     * 查看最新
     *
     * @param dto
     * @return
     */
    @PostMapping("/loadnew")
    public ResponseResult loadNew(@RequestBody ArticleHomeDto dto) {
        return apArticleService.load(dto,ArticleConstants.LOADTYPE_LOAD_NEW);
    }


}
